//
//  ysTableViewController.m
//  jiaxingOASystem
//
//  Created by michael on 16/9/13.
//  Copyright © 2016年 czd. All rights reserved.
//
#import "OADepartmentModel.h"

#import "GDataDefines.h"
#import "ysTableViewController.h"
#import "xbview.h"
#import "MHDatePicker.h"
#import "OASelectDepartmentController.h"
@interface ysTableViewController ()
@property(nonatomic,strong)NSMutableArray * departments;//发送
@property(nonatomic,strong)NSMutableArray * department;//保存
@property(nonatomic,strong)NSMutableArray * subItems;
@property (strong, nonatomic)  UITextView *nameField;
@property (strong, nonatomic)  UITextView *bumenField;
@property (strong, nonatomic)  UITextView *shenfenField;
@property (strong, nonatomic)  UITextView *phoneField;
@property (strong, nonatomic)  UITextView *zhiwuField;
@property (strong, nonatomic)  UITextView *zhicengField;
@property (strong, nonatomic)  UITextView *shiyouField;
@property (strong, nonatomic)  UITextView *chengshiField;
@property (strong, nonatomic)  UITextView *shijianField;
@property (strong, nonatomic)  UIButton *button1;
@property (strong, nonatomic)  UIButton *button2;
@property (strong, nonatomic) MHDatePicker *selectDatePicker;
@property (nonatomic, copy)NSString * timebeforestring;
@property (nonatomic, copy)NSString * timeafterstring;
@property (strong ,nonatomic)xbview *selectview;
@property (strong,nonatomic)NSString *typestring;
@property(nonatomic,copy)NSString * body;
@property(nonatomic,copy)NSString * time;
@property (nonatomic,copy)NSString *infoString0;
@property (nonatomic,copy)NSString *infoString;
@property(nonatomic,strong)OADetailDispatchModel * detailModel ;

// 字符串
@property (nonatomic,copy)NSString *namestring;
@property (nonatomic,copy)NSString *bumenstring;
@end

@implementation ysTableViewController
-(NSMutableArray*)subItems{
    if (_subItems ==nil) {
        _subItems = [NSMutableArray array];
    }
    return _subItems;

}
- (void)viewDidLoad {
    [super viewDidLoad];
        [self _initView];
        [self requestdata];
    self.title = @"因私出国(境)报告登记表";
    self.view.backgroundColor = [UIColor whiteColor];

   //点击手势
 UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(keybordDown)];
    [self.view addGestureRecognizer:tap];

        
    
    // Do any additional setup after loading the view.
}
- (void)_initView{
_tableView  = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, KScreenWidth, KScreenHeight-47-64) style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;

UIButton *savebutton = [UIButton buttonWithType:UIButtonTypeCustom];
[savebutton setTitle:@"保存" forState:UIControlStateNormal];
[savebutton setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
savebutton.frame = CGRectMake(0, _tableView.bottom, .5*KScreenWidth, 47);

UIButton *cilcuationbutton = [UIButton buttonWithType:UIButtonTypeCustom];
[cilcuationbutton setTitle:@"发送" forState:UIControlStateNormal];
cilcuationbutton.frame = CGRectMake(savebutton.right, _tableView.bottom, .5*KScreenWidth, 47);
[cilcuationbutton setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
savebutton.backgroundColor = [UIColor whiteColor];
cilcuationbutton.backgroundColor = [UIColor whiteColor
];
[savebutton addTarget:self action:@selector(saveAction) forControlEvents:UIControlEventTouchUpInside];
[cilcuationbutton addTarget:self action:@selector(cilcuationAction) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:savebutton];
[self.view addSubview:cilcuationbutton];
 
[self.view addSubview:_tableView];

}
- (void)requestdata{
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray * array = @[@{@"userId":userId}];
    [HttpTools postWithURL:KexchdataURL arrays:array method:@"createAbroadDoc" success:^(id JSON) {
    NSLog(@"=====%@",JSON);
   
        
        self.detailModel = [self getDetailModel:JSON];
        _namestring = _detailModel.name;
        _bumenstring = _detailModel.person;
        [self.tableView reloadData];
                [MBProgressHUD hideAllHUDsForView:self.view animated:YES];

    } failure:^(NSError *error) {
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
    }];


}
//获取解析得到的数据。
-( OADetailDispatchModel *)getDetailModel:(NSString*)dataString;
{
    NSData * data = [dataString dataUsingEncoding:NSUTF8StringEncoding];
    OADetailDispatchModel * detailModel = [[OADetailDispatchModel alloc]init];
    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData: data options:0 error:nil];
    //获取根节点（Users）
    GDataXMLElement *rootElement = [doc rootElement];
    //获取根节点下的节点（User）
    NSArray *rootData= [rootElement elementsForName:@"数据"];
    for (GDataXMLElement *subData in rootData) {
        NSArray * tempArray = [subData elementsForName:@"数据要素"];
        for (GDataXMLElement *data in tempArray) {
            GDataXMLElement *documentElement= [[data elementsForName:@"GwOrigUnit"] objectAtIndex:0];
            detailModel.name = [documentElement stringValue];
//                       GDataXMLElement *filestep= [[data elementsForName:@"GwOrigUnit"] objectAtIndex:0];
//            detailModel.workname = [filestep stringValue];
             GDataXMLElement *filestep1= [[data elementsForName:@"GwNum"] objectAtIndex:0];
            detailModel.person = [filestep1 stringValue];
             GDataXMLElement *filestep2= [[data elementsForName:@"GwRegister"] objectAtIndex:0];
            detailModel.data = [filestep2 stringValue];
            
            GDataXMLElement *fileId= [[data elementsForName:@"唯一标识"] objectAtIndex:0];
            detailModel.fileId = [fileId stringValue];
            

        }
    }
    
    
    
    return detailModel;
    
}
- (void)textViewDidChange:(UITextView *)textView
{
if(textView ==_nameField){
_namestring = _nameField.text;
}
if(textView ==_bumenField){
_bumenstring = _bumenField.text;
}


}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
//if (textView == _TextField2||textView == _TextField1||textView == _dayField) {
//    [UIView animateWithDuration:0.2 animations:^{
//    self.view.transform = CGAffineTransformMakeTranslation(0, -100);
//    }];
//
//}
UIView *view = textView.superview;

while (![view isKindOfClass:[UITableViewCell class]]) {

view = [view superview];

}

UITableViewCell *cell = (UITableViewCell*)view;

CGRect rect = [cell convertRect:cell.frame toView:self.view];

if (rect.origin.y / 2 + rect.size.height>=KScreenHeight/2) {

self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 216, 0);

[self.tableView scrollToRowAtIndexPath:[self.tableView indexPathForCell:cell] atScrollPosition:UITableViewScrollPositionMiddle animated:YES];

}





  
    return YES;
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

 [UIView animateWithDuration:0.2 animations:^{
         self.view.transform = CGAffineTransformIdentity;
    }];
    return YES;
}
- (void)textViewDidEndEditing:(UITextView *)textView{

if (textView == _shijianField || textView == _chengshiField || textView == _shiyouField || textView == _zhicengField|| textView == _zhiwuField) {
        [UIView animateWithDuration:0.2 animations:^{
         self.tableView.transform = CGAffineTransformIdentity;
    }];

}
 
}
- (void)saveAction{
[self keybordDown];
 if ([self.nameField.text length] == 0) {
        [self.view makeToast:@"对不起，你的姓名为空"];
        return;
    }
if ([self.bumenField.text length] == 0) {
        [self.view makeToast:@"对不起，你的所在部门为空"];
        return;
    }
if ([self.shenfenField.text length] == 0) {
        [self.view makeToast:@"对不起，你的身份证号为空"];
        return;
    }if ([self.phoneField.text length] == 0) {
        [self.view makeToast:@"对不起，你的电话为空"];
        return;
    }if ([self.zhiwuField.text length] == 0) {
        [self.view makeToast:@"对不起，你的职务为空"];
        return;
    }if ([self.zhicengField.text length] == 0) {
        [self.view makeToast:@"对不起，你的职称为空"];
        return;
    }
    if ([self.shiyouField.text length] == 0) {
        [self.view makeToast:@"对不起，你的出国事由为空"];
        return;
    }
if ([self.chengshiField.text length] == 0) {
        [self.view makeToast:@"对不起，你的所到国及城市为空"];
        return;
    }
if ([self.shijianField.text length] == 0) {
        [self.view makeToast:@"对不起，你的回国时间为空"];
        return;
    }
if ([_selectview.orderString isEqualToString:@"0"]) {
    _typestring = @"男";
}else{
  _typestring = @"女";


}
if ([_timeafterstring length]==0 ) {
            [self.view makeToast:@"对不起，你的滞留时间为空"];

}
else if ([_timebeforestring length]==0 ) {
            [self.view makeToast:@"对不起，你的滞留时间为空"];

}else{


_time = [NSString stringWithFormat:@"%@到%@",_timebeforestring,_timeafterstring];
}
if (_nameField.text!=nil&&_bumenField.text!=nil&&_shenfenField!=nil&&_phoneField.text!=nil&&_zhiwuField.text!=nil&&_zhicengField.text!=nil&&_shiyouField!=nil&&_shijianField!=nil&&_chengshiField!=nil&&_timeafterstring!=nil&&_timebeforestring!=nil){

self.body = [NSString stringWithFormat:@"&lt;?xml version=\'1.0\' encoding=\'utf-8\'?&gt;\n"
                     "&lt;交换 xmlns=\'exch.jhsx.gov.cn/data\' xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\'&gt;\n"
                     "&lt;数据&gt;\n"
                     "&lt;数据要素&gt;\n"
                     "&lt;唯一标识&gt;\n"
                     "%@"
                     "&lt;/唯一标识&gt;\n"
                     "&lt;GwOrigUnit  name='姓名'&gt;\n"
                     "%@"
                     "&lt;/GwOrigUnit&gt;\n"
                     "&lt;GwSubject  name='性别'&gt;\n"
                     "%@"
                     "&lt;/GwSubject&gt;\n"
                     "&lt;GwNum  name='所在部门'&gt;\n"
                     "%@"
                     "&lt;/GwNum&gt;\n"
                     "&lt;GwIssueDate  name='身份证号'&gt;\n"
                     "%@"
                     "&lt;/GwIssueDate&gt;\n"
                     "&lt;GwSwClass  name='联系电话'&gt;\n"
                     "%@"
                     "&lt;/GwSwClass&gt;\n"
                     "&lt;swfs  name='职  务'&gt;\n"
                     "%@"
                     "&lt;/swfs&gt;\n"
                     "&lt;GwHurry  name='职  称'&gt;\n"
                     "%@"
                     "&lt;/GwHurry&gt;\n"
                     "&lt;sendtype  name='因私出国(境)事由'&gt;\n"
                     "%@"
                     "&lt;/sendtype&gt;\n"
                     "&lt;GwFileClass  name='出国(境)所到国及城市'&gt;\n"
                     "%@"
                     "&lt;/GwFileClass&gt;\n"
                     "&lt;GwRegister  name='国(境)外停留时间'&gt;\n"
                     "%@"
                     "&lt;/GwRegister&gt;\n"
                     "&lt;sendmemo  name='回国时间'&gt;\n"
                     "%@"
                     "&lt;/sendmemo&gt;\n"
                     "&lt;/数据要素&gt;\n"
                      "&lt;数据对照&gt;\n"
                       "&lt;/数据对照&gt;\n"
                       "&lt;正文实体&gt;\n"
                       "&lt;/正文实体&gt;\n"
                       "&lt;数据实体&gt;\n"
                       "&lt;/数据实体&gt;\n"
                     "&lt;/数据&gt;\n"
                     "&lt;/交换&gt;",
                     self.detailModel.fileId,
             
                     self.nameField.text,
                     self.typestring,
                     self.bumenField.text,
                     self.shenfenField.text,
                        self.phoneField.text,
                    self.zhiwuField.text,
                    self.zhicengField.text,
             
                     self.shiyouField.text,
                     self.chengshiField.text,
                     self.time,
                     self.shijianField.text
];



  NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];

    NSArray * array =@[@{@"userId":_detailModel.fileId},@{@"sName":userId},@{@"formxml":self.body}];
    [HttpTools postWithURL:KexchdataURL arrays:array method:@"setSaveDoc"  success:^(id JSON) {
    _infoString0 = nil;
    [MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:YES];
     NSData * data = [JSON dataUsingEncoding:NSUTF8StringEncoding];
     GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData: data options:0 error:nil];
    GDataXMLElement *rootElement = [doc rootElement];
      
          NSArray *infoData= [rootElement elementsForName:@"info"];
    for (int i = 0;i<[infoData count];i++)
    {
        GDataXMLElement *infoElement = [infoData objectAtIndex:i];
        self.infoString0 = [infoElement stringValue];
    }
    if ([self.infoString0 isEqualToString:@"19"]) { //成功发送，提交下一办理人
        
        [self.view.window makeToast:@"保存成功"];
       
    }
          
    else if ([self.infoString0 isEqualToString:@"1044"]){
    
    [self.view.window makeToast:@"服务器出错"];

    }else{
    
    [self.view.window makeToast:@"保存失败"];
    }
   } failure:^(NSError *error) {
        [self.view.window makeToast:@"保存失败"];
    }];
}



}
- (void)cilcuationAction{
[self keybordDown];
 if ([self.nameField.text length] == 0) {
        [self.view makeToast:@"对不起，你的姓名为空"];
        return;
    }
if ([self.bumenField.text length] == 0) {
        [self.view makeToast:@"对不起，你的所在部门为空"];
        return;
    }
if ([self.shenfenField.text length] == 0) {
        [self.view makeToast:@"对不起，你的身份证号为空"];
        return;
    }if ([self.phoneField.text length] == 0) {
        [self.view makeToast:@"对不起，你的电话为空"];
        return;
    }if ([self.zhiwuField.text length] == 0) {
        [self.view makeToast:@"对不起，你的职务为空"];
        return;
    }if ([self.zhicengField.text length] == 0) {
        [self.view makeToast:@"对不起，你的职称为空"];
        return;
    }
    if ([self.shiyouField.text length] == 0) {
        [self.view makeToast:@"对不起，你的出国事由为空"];
        return;
    }
if ([self.chengshiField.text length] == 0) {
        [self.view makeToast:@"对不起，你的所到国及城市为空"];
        return;
    }
if ([self.shijianField.text length] == 0) {
        [self.view makeToast:@"对不起，你的回国时间为空"];
        return;
    }
if ([_selectview.orderString isEqualToString:@"0"]) {
    _typestring = @"男";
}else{
  _typestring = @"女";


}
if ([_timeafterstring length]==0 ) {
            [self.view makeToast:@"对不起，你的滞留时间为空"];

}
else if ([_timebeforestring length]==0 ) {
            [self.view makeToast:@"对不起，你的滞留时间为空"];

}else{


_time = [NSString stringWithFormat:@"%@到%@",_timebeforestring,_timeafterstring];
}
if (_nameField.text!=nil&&_bumenField.text!=nil&&_shenfenField!=nil&&_phoneField.text!=nil&&_zhiwuField.text!=nil&&_zhicengField.text!=nil&&_shiyouField!=nil&&_shijianField!=nil&&_chengshiField!=nil&&_timeafterstring!=nil&&_timebeforestring!=nil){

self.body = [NSString stringWithFormat:@"&lt;?xml version=\'1.0\' encoding=\'utf-8\'?&gt;\n"
                     "&lt;交换 xmlns=\'exch.jhsx.gov.cn/data\' xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\'&gt;\n"
                     "&lt;数据&gt;\n"
                     "&lt;数据要素&gt;\n"
                     "&lt;唯一标识&gt;\n"
                     "%@"
                     "&lt;/唯一标识&gt;\n"
                     "&lt;GwOrigUnit  name='姓名'&gt;\n"
                     "%@"
                     "&lt;/GwOrigUnit&gt;\n"
                     "&lt;GwSubject  name='性别'&gt;\n"
                     "%@"
                     "&lt;/GwSubject&gt;\n"
                     "&lt;GwNum  name='所在部门'&gt;\n"
                     "%@"
                     "&lt;/GwNum&gt;\n"
                     "&lt;GwIssueDate  name='身份证号'&gt;\n"
                     "%@"
                     "&lt;/GwIssueDate&gt;\n"
                     "&lt;GwSwClass  name='联系电话'&gt;\n"
                     "%@"
                     "&lt;/GwSwClass&gt;\n"
                     "&lt;swfs  name='职  务'&gt;\n"
                     "%@"
                     "&lt;/swfs&gt;\n"
                     "&lt;GwHurry  name='职  称'&gt;\n"
                     "%@"
                     "&lt;/GwHurry&gt;\n"
                     "&lt;sendtype  name='因私出国(境)事由'&gt;\n"
                     "%@"
                     "&lt;/sendtype&gt;\n"
                     "&lt;GwFileClass  name='出国(境)所到国及城市'&gt;\n"
                     "%@"
                     "&lt;/GwFileClass&gt;\n"
                     "&lt;GwRegister  name='国(境)外停留时间'&gt;\n"
                     "%@"
                     "&lt;/GwRegister&gt;\n"
                     "&lt;sendmemo  name='回国时间'&gt;\n"
                     "%@"
                     "&lt;/sendmemo&gt;\n"
                     "&lt;/数据要素&gt;\n"
                      "&lt;数据对照&gt;\n"
                       "&lt;/数据对照&gt;\n"
                       "&lt;正文实体&gt;\n"
                       "&lt;/正文实体&gt;\n"
                       "&lt;数据实体&gt;\n"
                       "&lt;/数据实体&gt;\n"
                     "&lt;/数据&gt;\n"
                     "&lt;/交换&gt;",
                     self.detailModel.fileId,
             
                     self.nameField.text,
                     self.typestring,
                     self.bumenField.text,
                     self.shenfenField.text,
                        self.phoneField.text,
                    self.zhiwuField.text,
                    self.zhicengField.text,
             
                     self.shiyouField.text,
                     self.chengshiField.text,
                     self.time,
                     self.shijianField.text
];



  NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];

    NSArray * array =@[@{@"userId":_detailModel.fileId},@{@"sName":userId},@{@"formxml":self.body}];
    [HttpTools postWithURL:KexchdataURL arrays:array method:@"setSaveDoc"  success:^(id JSON) {
    _infoString0 = nil;
    [MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:YES];
     NSData * data = [JSON dataUsingEncoding:NSUTF8StringEncoding];
     GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData: data options:0 error:nil];
    GDataXMLElement *rootElement = [doc rootElement];
      
          NSArray *infoData= [rootElement elementsForName:@"info"];
    for (int i = 0;i<[infoData count];i++)
    {
        GDataXMLElement *infoElement = [infoData objectAtIndex:i];
        self.infoString0 = [infoElement stringValue];
    }
    if ([self.infoString0 isEqualToString:@"19"]) { //成功发送，提交下一办理人
        
        [self.view.window makeToast:@"保存成功"];
               [self setSubmitWork];

    }
          
    else if ([self.infoString0 isEqualToString:@"1044"]){
    
    [self.view.window makeToast:@"服务器出错"];

    }else{
    
    [self.view.window makeToast:@"保存失败"];
    }
   } failure:^(NSError *error) {
        [self.view.window makeToast:@"保存失败"];
    }];
}



}

- (void)setSubmitWork{
    __weak typeof(self) weakSelf = self;

 NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];

 NSArray * array =@[@{@"userId":_detailModel.fileId},@{@"sName":userId},@{@"formxml":self.body}];
[HttpTools postWithURL:KexchdataURL arrays:array method:KSetSubmitWorkMethod success:^(id JSON) {
        self.departments = [self dataWith:JSON];
        
if ([self.infoString isEqualToString:@"11"]) { //成功发送，提交下一办理人
            
            [UIAlertView showWithTitle:@"提示" message:@"发送成功" cancelButtonTitle:@"确定" otherButtonTitles:nil tapBlock:^(UIAlertView *alertView, NSInteger buttonIndex) {
//                [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshOADetailData" object:nil];
              [self.navigationController popViewControllerAnimated:YES];
                                  }];
            
        }else if ([self.infoString isEqualToString:@"12"]) { //返回环节信息
              OASelectDepartmentController*    selectVC = [[OASelectDepartmentController alloc]init];
              UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barButtonItem;

            selectVC.subItems = self.subItems;
            selectVC.body = self.body;
            selectVC.detailPatchModel = self.detailModel;
//            selectVC.attachmentArray = self.attachmentArray;
            selectVC.departments = self.departments;
               [weakSelf.navigationController pushViewController:selectVC animated:YES];
            

        }else if ([self.infoString isEqualToString:@"13"]) {//返回人员列表
            //            OASelectPersonController * selectPersonVC = [[OASelectPersonController alloc]init];
            //            selectPersonVC.personArray = self.personArray;
            //            selectPersonVC.body = self.body;
            //            selectPersonVC.setpString = self.setpString;
            //            if (self.detailModel ) {
            //                selectPersonVC.fileId = self.detailModel.fileId;
            //            }else if (self.detailPatchModel){
            //                selectPersonVC.fileId = self.detailPatchModel.fileId;
            //            }
            //
            //            [self.navigationController pushViewController:selectPersonVC animated:YES];
      
            
            
        }else if ([self.infoString isEqualToString:@"14"]){ //返回树
            //            OASelectPersonSecondController * selectPersonVC = [[OASelectPersonSecondController alloc]init];
            //            selectPersonVC.personArray = self.personArray;
            //            selectPersonVC.body = self.body;
            //            selectPersonVC.setpString = self.setpString;
            //            if (self.detailModel ) {
            //                selectPersonVC.fileId = self.detailModel.fileId;
            //            }else if (self.detailPatchModel){
            //                selectPersonVC.fileId = self.detailPatchModel.fileId;
            //            }
            //            selectPersonVC.groupArray = self.groupArray;
            //            selectPersonVC.rowArray = self.rowArray;
            //            [self.navigationController pushViewController:selectPersonVC animated:YES];
            
        }
    } failure:^(NSError *error) {
        [MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:YES];
    }];




}
#pragma mark 数据解析

-(NSMutableArray*)dataWith:(NSString*)dataString
{
    NSData * data = [dataString dataUsingEncoding:NSUTF8StringEncoding];
    NSMutableArray *arrData = [[NSMutableArray alloc]init];
    NSMutableArray * subData = [NSMutableArray array];
    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData: data options:0 error:nil];
    GDataXMLElement *rootElement = [doc rootElement];
    NSArray *users = [rootElement children];
    for (int i = 0;i<[users count];i++) {
        GDataXMLElement *ele = [users objectAtIndex:i];
        if ([[ele name] isEqualToString:@"环节"]){
            OADepartmentModel * model = [[OADepartmentModel alloc]init];
            model.department = [[ele attributeForName:@"流向"] stringValue];
            for (int j=0; j<[ele childCount]; j++) {
                GDataXMLElement  *subItem = [ele childAtIndex:j];
                [subData addObject:subItem.stringValue];
            }
            [arrData addObject:model];
        }
    }
    self.subItems = subData; //选中 需要提交得数据
    NSArray *infoData= [rootElement elementsForName:@"info"];
    for (int i = 0;i<[infoData count];i++)
    {
        GDataXMLElement *infoElement = [infoData objectAtIndex:i];
        self.infoString = [infoElement stringValue];
    }
    
    return arrData;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    [self.view endEditing:YES];
    return YES;
}
- (void)keybordDown {

    
    [self.view endEditing:YES];
        }

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{
return 11;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row==0) {

 static NSString *cellid0 = @"cell0";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid0];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid0];
              UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"姓名 :";
    
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
      _nameField = [[UITextView alloc]init];
      _nameField.frame = CGRectMake(label.right, label.top+10, KScreenWidth-120, cell.height-10);
     // UIColor *myColor = [UIColor colorWithWhite:0.5 alpha:0.2];
    //  _nameField.backgroundColor = myColor;
 [_nameField setFont:[UIFont systemFontOfSize:13]];
 _nameField.textAlignment = NSTextAlignmentLeft;
      _nameField.delegate = self;
      _nameField.text = _namestring;
       [cell.contentView addSubview:_nameField];
       }
               _nameField.text = _namestring;

             return cell;

}
else if (indexPath.row==1) {
    
  
static NSString *cellid1 = @"cell1";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid1];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid1];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"性别 :";
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
      _selectview = [xbview checkBoxFootView];
      _selectview.frame = CGRectMake(label.right, label.top, 150, label.height);
       [cell.contentView addSubview:_selectview];
       }
             return cell;

}
else if(indexPath.row == 2){

static NSString *cellid2 = @"cell2";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid2];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid2];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"所在部门 :";
    
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
      _bumenField = [[UITextView alloc]init];
      _bumenField.frame = CGRectMake(label.right, label.top+10, KScreenWidth-120, cell.height-10);
     // UIColor *myColor = [UIColor colorWithWhite:0.5 alpha:0.2];
    //  _nameField.backgroundColor = myColor;
 [_bumenField setFont:[UIFont systemFontOfSize:13]];
 _bumenField.textAlignment = NSTextAlignmentLeft;
      _bumenField.delegate = self;
       [cell.contentView addSubview:_bumenField];
       }
               _bumenField.text = _bumenstring;

             return cell;



}
else if(indexPath.row == 3){

 static NSString *cellid3 = @"cell3";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid3];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid3];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"身份证号 :";
    
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
      _shenfenField = [[UITextView alloc]init];
      _shenfenField.frame = CGRectMake(label.right, label.top+10, KScreenWidth-120, cell.height-10);
      _shenfenField.keyboardType = UIKeyboardTypeDecimalPad;

//        _nameField.text = _detailModel.name;
      UIColor *myColor = [UIColor colorWithWhite:0.5 alpha:0.2];
      _shenfenField.backgroundColor = myColor;
 [_shenfenField setFont:[UIFont systemFontOfSize:13]];
 _shenfenField.textAlignment = NSTextAlignmentLeft;
      _shenfenField.delegate = self;
       [cell.contentView addSubview:_shenfenField];
       }
             return cell;



}
else if(indexPath.row == 4){

static NSString *cellid4 = @"cell4";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid4];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid4];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"联系电话 :";
    
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
      _phoneField = [[UITextView alloc]init];
      _phoneField.frame = CGRectMake(label.right, label.top+10, KScreenWidth-120, cell.height-10);
          _phoneField.keyboardType = UIKeyboardTypeDecimalPad;

//        _nameField.text = _detailModel.name;
      UIColor *myColor = [UIColor colorWithWhite:0.5 alpha:0.2];
      _phoneField.backgroundColor = myColor;
 [_phoneField setFont:[UIFont systemFontOfSize:13]];
 _phoneField.textAlignment = NSTextAlignmentLeft;
      _phoneField.delegate = self;
       [cell.contentView addSubview:_phoneField];
       }
             return cell;



}

else if(indexPath.row == 5){

static NSString *cellid5 = @"cell5";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid5];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid5];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"职务 :";
    
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
      _zhiwuField = [[UITextView alloc]init];
      _zhiwuField.frame = CGRectMake(label.right, label.top+10, KScreenWidth-120, cell.height-10);

//        _nameField.text = _detailModel.name;
      UIColor *myColor = [UIColor colorWithWhite:0.5 alpha:0.2];
      _zhiwuField.backgroundColor = myColor;
 [_zhiwuField setFont:[UIFont systemFontOfSize:13]];
 _zhiwuField.textAlignment = NSTextAlignmentLeft;
      _zhiwuField.delegate = self;
       [cell.contentView addSubview:_zhiwuField];}
             return cell;



}
else if(indexPath.row == 6){

static NSString *cellid6 = @"cell6";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid6];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid6];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"职称 :";
    
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
      _zhicengField = [[UITextView alloc]init];
      _zhicengField.frame = CGRectMake(label.right, label.top+10, KScreenWidth-120, cell.height-10);

//        _nameField.text = _detailModel.name;
      UIColor *myColor = [UIColor colorWithWhite:0.5 alpha:0.2];
      _zhicengField.backgroundColor = myColor;
 [_zhicengField setFont:[UIFont systemFontOfSize:13]];
 _zhicengField.textAlignment = NSTextAlignmentLeft;
      _zhicengField.delegate = self;
       [cell.contentView addSubview:_zhicengField];
       }
             return cell;



}
else if(indexPath.row == 7){

static NSString *cellid7 = @"cell7";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid7];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid7];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"因私出国(境)事由 :";
          label.numberOfLines = 0;

    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
      _shiyouField = [[UITextView alloc]init];
      _shiyouField.frame = CGRectMake(label.right, label.top+10, KScreenWidth-120, cell.height-10);

//        _nameField.text = _detailModel.name;
      UIColor *myColor = [UIColor colorWithWhite:0.5 alpha:0.2];
      _shiyouField.backgroundColor = myColor;
 [_shiyouField setFont:[UIFont systemFontOfSize:13]];
 _shiyouField.textAlignment = NSTextAlignmentLeft;
      _shiyouField.delegate = self;
       [cell.contentView addSubview:_shiyouField];
       }
             return cell;



}
else if(indexPath.row == 8){

static NSString *cellid8 = @"cell8";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid8];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid8];      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"出国(境)所到国及城市 :";
          label.numberOfLines = 0;

    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
      _chengshiField = [[UITextView alloc]init];
      _chengshiField.frame = CGRectMake(label.right, label.top+10, KScreenWidth-120, cell.height-10);

//        _nameField.text = _detailModel.name;
      UIColor *myColor = [UIColor colorWithWhite:0.5 alpha:0.2];
      _chengshiField.backgroundColor = myColor;
 [_chengshiField setFont:[UIFont systemFontOfSize:13]];
 _chengshiField.textAlignment = NSTextAlignmentLeft;
      _chengshiField.delegate = self;
       [cell.contentView addSubview:_chengshiField];
       }
             return cell;



}
else if(indexPath.row == 9){

static NSString *cellid9 = @"cell9";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid9];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid9];          UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
      label.numberOfLines = 0;
    label.text = @"国(境)外停留时间 :";
    
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
    _button1 = [UIButton buttonWithType:UIButtonTypeCustom];
      _button1.frame = CGRectMake(label.right, label.top, 100, label.height);
//    _button1.backgroundColor = [UIColor yellowColor];
      [_button1 setTitle:@"开始时间" forState:UIControlStateNormal];
    _button1.titleLabel.font = [UIFont systemFontOfSize: 12.0];
    
       _button2 = [UIButton buttonWithType:UIButtonTypeCustom];
      _button2.frame = CGRectMake(_button1.right, label.top, 110, label.height);
      [_button2 setTitle:@"结束时间" forState:UIControlStateNormal];
          _button2.titleLabel.font = [UIFont systemFontOfSize: 12.0];
      [_button1 setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
      [_button2 setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
      [_button1 addTarget:self action:@selector(action1) forControlEvents:UIControlEventTouchUpInside];
[_button2 addTarget:self action:@selector(action2) forControlEvents:UIControlEventTouchUpInside];
       [cell.contentView addSubview:_button1];
       [cell.contentView addSubview:_button2];}
             return cell;



}else {

static NSString *cellid10 = @"cell10";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid10];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid10];          UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"回国时间 :";
    
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
      _shijianField = [[UITextView alloc]init];
      _shijianField.frame = CGRectMake(label.right, label.top+10, KScreenWidth-120, cell.height-10);

//        _nameField.text = _detailModel.name;
      UIColor *myColor = [UIColor colorWithWhite:0.5 alpha:0.2];
      _shijianField.backgroundColor = myColor;
 [_shijianField setFont:[UIFont systemFontOfSize:13]];
 _shijianField.textAlignment = NSTextAlignmentLeft;
      _shijianField.delegate = self;
       [cell.contentView addSubview:_shijianField];
       }
             return cell;



}
}
- (void)action1{
 _selectDatePicker = [[MHDatePicker alloc] init];
    _selectDatePicker.isBeforeTime = YES;
    _selectDatePicker.datePickerMode = UIDatePickerModeDate;
    
    __weak typeof(self) weakSelf = self;
    [_selectDatePicker didFinishSelectedDate:^(NSDate *selectedDate) {
//        NSString *string = [NSString stringWithFormat:@"%@",[NSDate dateWithTimeInterval:3600*8 sinceDate:selectedDate]];
//        weakSelf.myLabel2.text = string;
      NSString *string = [weakSelf dateStringWithDate:selectedDate DateFormat:@"yyyy年MM月dd日"];
      _timebeforestring = string;
      [weakSelf.button1 setTitle:string forState:UIControlStateNormal];
    }];

}
- (void)action2{
_selectDatePicker = [[MHDatePicker alloc] init];
    _selectDatePicker.isBeforeTime = YES;
    _selectDatePicker.datePickerMode = UIDatePickerModeDate;
    
    __weak typeof(self) weakSelf = self;
    [_selectDatePicker didFinishSelectedDate:^(NSDate *selectedDate) {
//        NSString *string = [NSString stringWithFormat:@"%@",[NSDate dateWithTimeInterval:3600*8 sinceDate:selectedDate]];
//        weakSelf.myLabel2.text = string;
      NSString *string = [weakSelf dateStringWithDate:selectedDate DateFormat:@"yyyy年MM月dd日"];
        _timeafterstring = string;
      [weakSelf.button2 setTitle:[NSString stringWithFormat:@"%@",string] forState:UIControlStateNormal];
    }];

}
- (NSString *)dateStringWithDate:(NSDate *)date DateFormat:(NSString *)dateFormat
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:dateFormat];
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]];
    NSString *str = [dateFormatter stringFromDate:date];
    return str ? str : @"";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
